<%@page import="entities.Category"%>
<%@page import="java.util.Map"%>
<%@page import="helpers.DateHelper"%>
<%@page import="entities.Article"%>
<%@page import="helpers.StringHelper"%>
<%@page import="java.net.URLEncoder"%>
<%@page import="helpers.PaginatorHelper"%>
<%@page import="helpers.UrlHelper"%>
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
ArrayList<Article> articles = (ArrayList<Article>) request.getAttribute("articles");
Map<String, Category> categories = (Map<String, Category>) request.getAttribute("categories");
int pages = (Integer) request.getAttribute("page");
boolean nextPage = (Boolean) request.getAttribute("nextPage");
boolean prevPage = (Boolean) request.getAttribute("prevPage");
PaginatorHelper paginator = (PaginatorHelper) request.getAttribute("paginator");
%>
<jsp:include page="/admin/layouts/header.jsp" />

<script type="text/javascript" src="/admin/js/article_list.js"></script>
<script type="text/javascript" src="/admin/js/list_form.js"></script>
<script type="text/javascript">
<!--
var server = "<%=UrlHelper.getServerUrl(request)%>";
//-->
</script>
        <div class="maincontent noright">
        	<div class="maincontentinner">
            	
                <ul class="maintabmenu">
                	<li class="current"><a href="/admin/article/list">Article Manager</a></li>
                	<li><a href="/admin/article/search">Search Article</a></li>
                	<li><a href="/admin/article/add">Add New Article</a></li>
                </ul><!--maintabmenu-->
                
                <div class="content">
                	<jsp:include page="/admin/elements/message_box.jsp" />
                	
                	<div class="">
                		<a class="btn btn_world" href="/admin/article/search"><span>Search Article</span></a> &nbsp;
                		<a class="btn btn_world" href="/admin/article/add"><span>New Article</span></a>
                	</div>
                	<br />
                	
                	<div class="contenttitle radiusbottom0">
	                	<h2 class="table"><span>List Article</span></h2>
	                </div>
	                
	                <div class="tableoptions">
	                    <select class="radius3 action-value">
	                        <option value="status_active">Change to Status Active</option>
	                        <option value="status_inactive">Change to Status Inactive</option>
	                        <option value="delete">Delete all selected</option>
	                    </select> &nbsp;
	                    <button class="radius3 apply-change">Apply</button>
	                </div>
	                
	                <table cellspacing="0" cellpadding="0" border="0" class="stdtable stdtablecb" id="list-table">
	                    <colgroup>
	                        <col class="con0">
	                        <col class="con1">
	                        <col class="con0">
	                        <col class="con1">
	                        <col class="con0">
	                        <col class="con1">
	                        <col class="con0">
	                    </colgroup>
	                    <thead>
	                        <tr>
	                        	<th class="head0"><span class="checkbox"><input type="checkbox" class="checkall"></span></th>
	                            <th class="head1">Title</th>
	                            <th class="head0">Author</th>
	                            <th class="head1">Category</th>
	                            <th class="head0">Publish</th>
	                            <th class="head1">Created</th>
	                            <th class="head0">Action</th>
	                        </tr>
	                    </thead>
	                    <tfoot>
	                        <tr>
	                        	<th class="head0"><span class="checkbox"><input type="checkbox" class="checkall"></span></th>
	                            <th class="head1">Title</th>
	                            <th class="head0">Author</th>
	                            <th class="head1">Category</th>
	                            <th class="head0">Publish</th>
	                            <th class="head1">Created</th>
	                            <th class="head0">Action</th>
	                        </tr>
	                    </tfoot>
	                    <tbody>
	                    	<% for (int i = 0; i < articles.size(); i++) { %>
	                        <tr>
	                        	<td class="center"><span class="checkbox"><input type="checkbox" value="<%=URLEncoder.encode(articles.get(i).getId())%>"></span></td>
	                            <td><%=StringHelper.cutString(articles.get(i).getTitle(), 15) %></td>
	                            <td class="center"><%=articles.get(i).getAuthorName() %></td>
	                            <td class="center">
	                            	<%
	                            	Category category = categories.get(articles.get(i).getCategory());
	                            	if (category != null) {
	                            	%>
	                            	<%=category.getName() %>
	                            	<% } else { %>
	                            	<%=articles.get(i).getCategory() %>
	                            	<% } %>
	                            </td>
	                            <td class="center">
	                            	<%
	                            	switch (articles.get(i).getStatus()) {
	                            		case 0: 
	                            			%>
	                            			Unpublish
	                            			<%
	                            			break;
	                            		case 1:
	                            			%>
	                            			Publish
	                            			<%
	                            			break;
	                            		case 2:
	                            			%>
	                            			UnReview
	                            			<%
	                            			break;
	                            	} 
	                            	%>
	                            </td>
	                            <td class="center"><%=DateHelper.getStringFromDate(articles.get(i).getCreated(), "dd-MM-yyyy")  %></td>
	                            <td class="center">
									<a title="Edit Article" href="/admin/article/edit/<%=articles.get(i).getId() %>" class="edit">
										Edit
									</a>&nbsp;
									<a title="Remove Article" href="/admin/article/delete/<%=articles.get(i).getId() %>" id="action_del" class="delete">
										Delete
									</a>
								</td>
	                        </tr>
	                        <% } %>
	                    </tbody>
	                </table>
	                <!-- paginate -->
	                <div class="dataTables_paginate paging_full_numbers" id="dyntable_paginate">
	                	<% if (prevPage) { %>
							<a class="previous paginate_button" id="dyntable_previous" href="<%=paginator.getPrev()%>">Previous</a>
						<% } else { %>
							<span class="previous paginate_button paginate_button_disabled" id="dyntable_previous">Previous</span>
						<% } %>
						<% if (nextPage) { %>
							<a class="next paginate_button" id="dyntable_next"  href="<%=paginator.getNext()%>">Next</a>
						<% } else { %>
							<span class="next paginate_button paginate_button_disabled" id="dyntable_next">Next</span>
						<% } %>
	                </div>
                </div><!--content-->
                
            </div><!--maincontentinner-->
            
            <jsp:include page="/admin/elements/copyright.jsp" />
            
        </div><!--maincontent-->
 
 <jsp:include page="/admin/layouts/footer.jsp">
    <jsp:param name="language" value="1" />
</jsp:include>